<template>
	<!--pages/integralOrder/integralOrder.wxml-->
	<view class="content">
		<view class="top">
			<view class="top-list">
				<text class="top-list-1">剩余{{integral_name}}</text>
				<text class="top-list-2">{{less_integral}}</text>
			</view>
			<view class="top-list top-list-style">
				<text class="top-list-1">使用{{integral_name}}</text>
				<text class="top-list-2">{{use_integral}}</text>
			</view>
		</view>
		<block v-for="(item, index) in orderList" :key="index">
			<view class="songs_item">
				<view class="msg">
					<view>
						<text class="span span2">{{item.remark}}</text>
						<view class="span span3">{{item.add_time}}</view>
					</view>
				</view>
				<view>
					<text
						:class="'span span2' + (item.i_type==1?' color':'')">{{item.i_type==1?'+':'-'}}{{item.integral}}</text>
				</view>
			</view>
		</block>
		<view class="kong" @tap="getMore" v-if="canLoad">获取更多</view>
		<view class="kong" v-if="empty">暂无记录</view>
		<view class="kong" v-else-if="!canLoad&&!empty">已经到底了</view>
	</view>
</template>

<script>
	// pages/integralOrder/integralOrder.js
	var app = getApp().globalData;

	export default {
		data() {
			return {
				orderList: [],
				page: 0,
				canLoad: true,
				empty: 0,
				less_integral: 0,
				use_integral: 0,
				integral_name:''
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			var that = this;
			that.integral_name = this.$store.integral_name;
			getApp().globalData.sendRequest({
				url: '/Vip/getSumIntegral',
				success: function(res) {
					if (res.status == 1) {
						that.setData({
							less_integral: res.less_integral,
							use_integral: res.use_integral
						});
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 1500,
							mask: true
						});
					}
				}
			});
			this.getData();
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			this.getData();
		},
		methods: {
			/**
			 * 获取数据
			 */
			getData: function() {
				if (this.canLoad) {
					var that = this;
					this.setData({
						canLoad: false
					});
					var page = parseInt(this.page) + 1;
					getApp().globalData.sendRequest({
						url: '/Vip/getIntegral',
						data: {
							page: page
						},
						success: function(res) {
							if (res.status == 1) {
								var list = [];

								if (page == 1) {
									list = res.data;
								} else {
									var order_info = res.data;
									list = that.orderList;
									list.push.apply(list, order_info);
								}

								var canLoad = true;

								if (res.data.length < res.count) {
									canLoad = false;
								}

								that.setData({
									orderList: list,
									page: page,
									canLoad: canLoad
								});
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 1500,
									mask: false
								});
							}
						}
					});
				}
			}
		}
	};
</script>
<style>
	@import "./integralOrder.css";
</style>
